<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" >
      <el-form-item label="姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件编号" prop="certificateId">
        <el-input
          v-model="queryParams.certificateId"
          placeholder="请输入证件编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="身份证号" prop="idNumber">
        <el-input
          v-model="queryParams.idNumber"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="预算科目" prop="budgetAccount">
        <el-select
          v-model="queryParams.budgetAccount"
          placeholder="请选择预算科目"
          clearable
        >
          <el-option
            v-for="dict in dict.type.yh_budget_account"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="预算项目" prop="budgetItems">
        <el-input
          v-model="queryParams.budgetItems"
          placeholder="请输入预算项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!--<el-form-item label="支出内容" prop="purpose">
        <el-input
          v-model="queryParams.purpose"
          placeholder="请输入支出内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
     <!-- <el-form-item label="报销月份" prop="reimbursementMonth" v-show="showSearch">
        <el-input
          v-model="queryParams.reimbursementMonth"
          placeholder="请输入报销月份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <!--<el-form-item label="报销情况" prop="reimbursementApply">
        <el-input
          v-model="queryParams.reimbursementApply"
          placeholder="请输入报销情况"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <br/>
      <div style="text-align: right;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
      </div>
    </el-form>
      <br/>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:cjl:budget:add']"
        >新增</el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:cjl:budget:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:cjl:budget:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:cjl:budget:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="budgetList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center" />
      <el-table-column label="姓名" align="center" prop="username" v-if="columns[0].visible"/>
      <el-table-column label="证件编号" align="center" prop="certificateId" v-if="columns[1].visible"/>
      <el-table-column label="身份证号" align="center" prop="idNumber" v-if="columns[2].visible"/>
      <el-table-column label="部门" align="center" prop="dept.deptName" v-if="columns[3].visible"/>
      <el-table-column label="预算科目" align="center" prop="budgetAccount" v-if="columns[4].visible">
      <template slot-scope="scope">
        <dict-tag :options="dict.type.yh_budget_account" :value="scope.row.budgetAccount"/>
      </template>
      </el-table-column>
      <el-table-column label="预算项目" align="center" prop="budgetItems" v-if="columns[5].visible"/>
      <el-table-column label="支出内容" align="center" prop="purpose" v-if="columns[6].visible"/>
      <el-table-column label="金额" align="center" prop="amount" v-if="columns[7].visible"/>
      <el-table-column label="报销月份" align="center" prop="reimbursementMonth" v-if="columns[8].visible"/>
      <el-table-column label="报销情况" align="center" prop="reimbursementApply" v-if="columns[9].visible"/>
      <el-table-column label="备注" align="center" prop="remark" v-if="columns[10].visible"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="160" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:cjl:budget:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:cjl:budget:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['module:cjl:budget:view']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改预算申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">预算申请信息</p>
            </el-divider>
          </el-header>
          <el-main>
        <el-row>
          <el-col :span="8">
            <el-form-item label="预算科目" prop="budgetAccount">
              <el-select v-model="form.budgetAccount" placeholder="请选择预算科目"  style="width: 100%">
                <el-option
                  v-for="dict in dict.type.yh_budget_account"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
              <!--<el-input v-model="form.budgetAccount" placeholder="请输入预算科目"/>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预算项目" prop="budgetItems">
              <el-input v-model="form.budgetItems" placeholder="请输入预算项目"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="金额" prop="amount">
              <el-input v-model="form.amount" placeholder="请输入金额"/>
            </el-form-item>
          </el-col>
        </el-row>
            <el-form-item label="支出内容" prop="purpose">
              <el-input v-model="form.purpose" type="textarea" placeholder="请输入支出内容" maxlength="100"/>
             <!-- <editor v-model="form.purpose" :min-height="120" placeholder="请输入支出内容"/>-->
            </el-form-item>
            <el-row>
          <el-col :span="8">
            <el-form-item label="报销月份" prop="reimbursementMonth">
              <el-input v-model="form.reimbursementMonth" placeholder="请输入报销月份"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="报销情况" prop="reimbursementApply">
              <el-input v-model="form.reimbursementApply" placeholder="请输入报销情况"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" maxlength="500"/>
        </el-form-item>
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看预算申请对话框 -->
    <el-dialog :title="view.title" :visible.sync="view.open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">基础信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="姓名" prop="username">
                  <el-input v-model="form.username" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="证件编号" prop="certificateId">
                  <el-input v-model="form.certificateId" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="身份证号" prop="idNumber">
                  <el-input v-model="form.idNumber"  readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">预算申请信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="预算科目" prop="budgetAccount">
                  <el-select v-model="form.budgetAccount"   style="width: 100%" disabled="true">
                    <el-option
                      v-for="dict in dict.type.yh_budget_account"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                  <!--<el-input v-model="form.budgetAccount" placeholder="请输入预算科目"/>-->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="预算项目" prop="budgetItems">
                  <el-input v-model="form.budgetItems"  readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="金额" prop="amount">
                  <el-input v-model="form.amount" readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="支出内容" prop="purpose">
              <el-input v-model="form.purpose" type="textarea"  readonly="true"/>
             <!-- <editor v-model="form.purpose" :min-height="192" readonly="true"/>-->
            </el-form-item>
            <el-row>
              <el-col :span="8">
                <el-form-item label="报销月份" prop="reimbursementMonth">
                  <el-input v-model="form.reimbursementMonth" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="报销情况" prop="reimbursementApply">
                  <el-input v-model="form.reimbursementApply" readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" readonly="true"/>
            </el-form-item>
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewCancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBudget, getBudget, delBudget, addBudget, updateBudget } from "@/api/module/cjl/budget";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import watermark from "watermark-dom";
export default {
  name: "Budget",
  dicts: ['yh_budget_account'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 预算申请表格数据
      budgetList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: null,
        certificateId: null,
        idNumber: null,
        deptid: null,
        budgetAccount: null,
        budgetItems: null,
        purpose: null,
        amount: null,
        reimbursementMonth: null,
        reimbursementApply: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null,
        orderByColumn:"createTime",
        isAsc:"desc"
      },
      // 表单参数
      form: {},
      view:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      // 列信息
      columns: [
        { key: 0, label: `姓名`, visible: true },
        { key: 1, label: `证件编号`, visible: true },
        { key: 2, label: `身份证号`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `预算科目`, visible: true },
        { key: 5, label: `预算项目`, visible: false },
        { key: 6, label: `支出内容`, visible: false },
        { key: 7, label: `金额`, visible: true },
        { key: 8, label: `报销月份`, visible: false },
        { key: 9, label: `报销情况`, visible: false },
        { key: 10, label: `备注`, visible: false },
      ],
      // 表单校验
      rules: {
        username: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        certificateId: [
          { required: true, message: "证件编号不能为空", trigger: "blur" },
        ],
        idNumber: [
          { required: true, message: "身份证号不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "部门不能为空", trigger: "blur" },
        ],
        budgetAccount: [
          { required: true, message: "预算科目不能为空", trigger: "blur" },
        ],
        amount: [
          { required: true, message: "金额不能为空", trigger: "blur" },
        ],
      }
    };
  },
  mounted() {
    watermark.load({ watermark_txt: "  "   });
  },
  created() {
    this.getList();
    this.getTreeselect();
  },
  methods: {
    indexMethod(index) {
      index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      return index
    },
    /** 查询预算申请列表 */
    getList() {
      this.loading = true;
      listBudget(this.queryParams).then(response => {
        this.budgetList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 返回按钮
    viewCancel() {
      this.view.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        username: null,
        certificateId: null,
        idNumber: null,
        deptid: null,
        budgetAccount: null,
        budgetItems: null,
        purpose: null,
        amount: null,
        reimbursementMonth: null,
        reimbursementApply: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.is=selection.map(item => item.certificateId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加预算申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBudget(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预算申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBudget(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBudget(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
     /* const id = row.id || this.ids
      getBudget(id).then(response => {
        this.form = response.data;
        this.view.open = true;
        this.view.title = "查看预算申请信息";
      });*/
      const id = row.id;
      this.$router.push({ path:"/zonghe/budget_detail", query: {id}});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const i=row.certificateId || this.is;
      this.$modal.confirm('是否确认删除证件编号为"' + i + '"的数据项？').then(function() {
        return delBudget(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/cjl/budget/export', {
        ...this.queryParams
      }, `budget_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
  .el-header, .el-footer {
    background-color: #FFFFFF;
    color: #333;
    text-align: left;
    line-height: 60px;
    font-style: oblique;

  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  /*对话框标题样式*/
  .el-dialog__title{
    /*color: #1ab394;*/
    font-weight: bold;
    font-size: 25px;
  }
</style>
